<!DOCTYPE html>
<html>
<head>
    <:include file="../common/css.html" title="客户管理"/>
</head>
<style type="text/css">
    #customerEditForm .layui-form-label {
        width: 81px;  /* 这里修改标题宽度 */
    }
    #customerEditForm .layui-input-block {
        margin-left: 111px;  /* 这里要比上面始终大30px */
    }
    .layui-table-cell {
        height: auto;
        line-height: 26px;
    }
    #kkfForm .layui-form-label {
        width: 100px;  /* 这里修改标题宽度 */
    }

    #kkfForm .layui-input-block {
        margin-left: 130px;  /* 这里要比上面始终大30px */
    }
</style>

<body>
<!-- 正文开始 -->
<div class="layui-fluid">

    <div class="layui-card card-box-shadow">
        <div class="layui-card-header">客户列表</div>
        <div class="layui-card-body">
            <!-- 表格工具栏 -->
            <form class="layui-form toolbar" lay-filter="customerTbSearchForm" >
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label w-auto">卡片：</label>
                        <div class="layui-input-inline mr0">
                            <input name="card" class="layui-input search_key" type="search" placeholder="卡片"/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label w-auto">姓名：</label>
                        <div class="layui-input-inline mr0">
                            <input name="name" class="layui-input search_key" type="search" placeholder="姓名"/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label w-auto">身份证：</label>
                        <div class="layui-input-inline mr0">
                            <input name="idCard" class="layui-input search_key" type="search" placeholder="身份证"/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label w-auto">电话：</label>
                        <div class="layui-input-inline mr0">
                            <input name="phone" class="layui-input search_key" type="search" placeholder="电话"/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label w-auto">缴费：</label>
                        <div class="layui-input-inline mr0">
                            <select id="payTimeSearch" name="payTime" lay-filter="payTimeSearch" lay-verify="" lay-search="">
                                <option value="">请选择</option>
                                <option value="已缴费">已缴费</option>
                                <option value="未缴费">未缴费</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label w-auto">停报：</label>
                        <div class="layui-input-inline mr0">
                            <select id="tbStateSearch" name="tbState" lay-filter="tbStateSearch" lay-verify="" lay-search="">
                                <option value="">请选择</option>
                                <option value="2">停报</option>
                                <option value="1">正常</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn icon-btn" lay-filter="customerTbSearch" id="customerTbSearch" lay-submit>
                            <i class="layui-icon">&#xe615;</i>搜索
                        </button>
                        <% if(so.hasPermission("customer:customer:save")){ %>
                        <button id="btnAdd" type="button" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>添加</button>
                        <% } %>
                    </div>
                </div>
            </form>
            <!-- 数据表格 -->
            <table id="customerTable" lay-filter="customerTable"></table>
        </div>
    </div>

    <div class="layui-card card-box-shadow">
        <div class="layui-card-header">历史记录</div>
        <div class="layui-card-body">

            <!-- 数据表格 -->
            <table id="payHistoryTable" lay-filter="payHistoryTable"></table>
        </div>
    </div>

</div>
<!-- 表格操作列 -->
<script type="text/html" id="customerTbBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="ysk">预收</a>
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="jf">缴费</a>
<!--    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="tb">停报</a>-->
<!--    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="kkf">开口</a>-->
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="tk">退款</a>
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="wg">违规</a>
	<% if(so.hasPermission("customer:customer:update")){ %>
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
    <% } %>
    <% if(so.hasPermission("customer:customer:remove")){ %>
    <a class="layui-btn layui-btn-danger layui-btn-xs"
       data-dropdown="#customerTbDelDrop{{d.LAY_INDEX}}" no-shade="true">删除</a>
    <% } %>
    <div class="dropdown-menu-nav dropdown-popconfirm dropdown-top-right layui-hide"
         id="customerTbDelDrop{{d.LAY_INDEX}}"
         style="max-width: 200px;white-space: normal;min-width: auto;margin-left: 10px;">
        <div class="dropdown-anchor"></div>
        <div class="dropdown-popconfirm-title">
            <i class="layui-icon layui-icon-help"></i>
            确定要删除{{d.name}}吗？
        </div>
        <div class="dropdown-popconfirm-btn">
            <a class="layui-btn" btn-cancel>取消</a>
            <a class="layui-btn layui-btn-normal" lay-event="del">确定</a>
        </div>
    </div>
</script>
<!-- 表格操作列 -->
<script type="text/html" id="picTbBar22">
    <img data-index="{{d.LAY_INDEX - 1}}" data-src="/file/{{d.pic}}" src="/file/{{d.pic}}" class="tb-img-circle" tb-img2 alt="" style="height: 24px;"/>
</script>
<!-- 表格操作列 -->
<script type="text/html" id="picTbBar">
{{#
    layui.each(d.pic.split(","), function(index, item){
    if(item!=null && item != ''){
}}
<img data-index="{{index}}" data-src="/file/{{item}}" src="/file/{{item}}" class="tb-img-circle" tb-img alt="" style="height: 24px;"/>
{{#
    }
    })
}}
</script>
<!-- 表格操作列 -->
<script type="text/html" id="payHistoryPicTbBar">
{{#
    layui.each(d.picAdd.split(","), function(index, item){
    if(item!=null && item != ''){
}}
<img data-index="{{index}}" data-src="/file/{{item}}" src="/file/{{item}}" class="tb-img-circle" tb-img alt="" style="height: 24px;"/>
{{#
    }
    })
}}
</script>
<!-- 表单弹窗 -->
<script type="text/html" id="customerEditDialog">
    <form id="customerEditForm" lay-filter="customerEditForm" class="layui-form model-form">
        <input name="id" id="id" type="hidden"/>
        <input name="companyId" type="hidden"/>
        <div class="layui-form-item layui-row">
            <div class="layui-col-md4">
                <label class="layui-form-label layui-form-required" id="card_update" style="text-decoration:underline;cursor: pointer;">卡片id</label>
                <div class="layui-input-block" style="position: relative">
                   <input id="card" name="card" type="text" class="layui-input" autocomplete="off"
                   lay-verType="tips" lay-verify="required" maxlength="20" placeholder="请使用读卡机"/>
                </div>
            </div>
            <div class="layui-col-md4">
                <label class="layui-form-label layui-form-required">姓名</label>
                <div class="layui-input-block">
                   <input id="name" name="name" type="text" class="layui-input" autocomplete="off"
                   lay-verType="tips" lay-verify="required" maxlength="20" placeholder="请输入姓名"/>
                </div>
            </div>
            <div class="layui-col-md4">
                <label class="layui-form-label layui-form-required">身份证</label>
                <div class="layui-input-block">
                   <input id="idCard" name="idCard" type="text" class="layui-input" autocomplete="off"
                   lay-verType="tips" lay-verify="required" maxlength="20" placeholder="请输入身份证"/>
                </div>
            </div>
        </div>
        <div class="layui-form-item layui-row">

            <div class="layui-col-md4">
                <label class="layui-form-label layui-form-required">电话</label>
                <div class="layui-input-block">
                    <input id="phone" name="phone" type="text" class="layui-input" autocomplete="off"
                           lay-verType="tips" lay-verify="required" maxlength="20" placeholder="请输入电话"/>
                </div>
            </div>
            <div class="layui-col-md4">
                <label class="layui-form-label ">地址</label>
                <div class="layui-input-block">
                    <input id="address" name="address" type="text" class="layui-input" autocomplete="off"
                           lay-verType="tips" lay-verify="" maxlength="40" placeholder="请输入地址"/>
                </div>
            </div>
            <div class="layui-col-md4">
                <label class="layui-form-label layui-form-required">总面积</label>
                <div class="layui-input-block">
                    <input id="totalArea" name="totalArea" type="text" class="layui-input" autocomplete="off"
                           lay-verType="tips" lay-verify="numberX|required" maxlength="15" placeholder="请输入总面积"/>
                </div>
            </div>
        </div>

        <div class="layui-form-item layui-row">
            <div class="layui-col-md4">
                <label class="layui-form-label ">供热面积</label>
                <div class="layui-input-block">
                    <input id="heatArea" name="heatArea" type="text" class="layui-input" autocomplete="off"
                           lay-verType="tips" lay-verify="numberX" maxlength="15" placeholder="请输入供热面积"/>
                </div>
            </div>
            <div class="layui-col-md4">
                <label class="layui-form-label ">商用面积</label>
                <div class="layui-input-block">
                    <input id="commercial" name="commercial" type="text" class="layui-input" autocomplete="off"
                           lay-verType="tips" lay-verify="numberX" maxlength="40" placeholder="请输入商用面积"/>
                </div>
            </div>
            <div class="layui-col-md4">
                <label class="layui-form-label ">民用面积</label>
                <div class="layui-input-block">
                    <input id="civil" name="civil" type="text" class="layui-input" autocomplete="off"
                           lay-verType="tips" lay-verify="numberX" maxlength="40" placeholder="请输入民用面积"/>
                </div>
            </div>
        </div>
        <div class="layui-form-item layui-row">
            <div class="layui-col-md4">
                <label class="layui-form-label ">商用热损</label>
                <div class="layui-input-block">
                    <input id="commercialUnuse" name="commercialUnuse" type="text" class="layui-input" autocomplete="off"
                           lay-verType="tips" lay-verify="numberX" maxlength="40" placeholder="请输入商用热损" />
                </div>
            </div>
            <div class="layui-col-md4">
                <label class="layui-form-label ">民用热损</label>
                <div class="layui-input-block">
                    <input id="civilUnuse" name="civilUnuse" type="text" class="layui-input" autocomplete="off"
                           lay-verType="tips" lay-verify="numberX" maxlength="40" placeholder="请输入民用热损" />
                </div>
            </div>
            <div class="layui-col-md4">
                <label class="layui-form-label ">总费用</label>
                <div class="layui-input-block">
                    <input id="price" name="price" type="text" class="layui-input" autocomplete="off"
                           lay-verType="tips" lay-verify="numberX" maxlength="40" placeholder="请输入民用热损"
                           readonly style="border: 0"/>
                </div>
            </div>
        </div>
        <div class="layui-form-item layui-row layui-hide">
            <div class="layui-col-md4">
                <label class="layui-form-label ">预付折扣(%)</label>
                <div class="layui-input-block">
                    <input id="advanceChargeDiscount" name="advanceChargeDiscount" type="text" class="layui-input" autocomplete="off"
                           lay-verType="tips" lay-verify="numberX" maxlength="40" placeholder="请输入预付折扣(100%)" />
                </div>
            </div>
        </div>
        <div class="layui-form-item layui-row layui-hide" id="divPayTime">
            <div class="layui-col-md4">
                <label class="layui-form-label ">缴费时间</label>
                <div class="layui-input-block">
                    <input id="payTimelie" name="payTime" type="text" class="layui-input" autocomplete="off"
                           lay-verType="tips" lay-verify="" maxlength="40" placeholder="请输入缴费时间" />
                </div>
            </div>
        </div>
        <div class="layui-form-item layui-row layui-hide" style="padding: 10px;padding-left: 40px;">
            <blockquote class="layui-elem-quote" id="illustrate"></blockquote>
        </div>
        <div class="layui-form-item layui-row">
            <div class="layui-col-md12">
                <label class="layui-form-label ">身份证照片</label>
                <div class="layui-input-block">
                    <button type="button" class="layui-btn" id="pic_upload">
                        <i class="layui-icon">&#xe67c;</i>上传图片
                    </button>
                    <input id="pic" name="pic" type="text" class="layui-input layui-hide" autocomplete="off"
                           lay-verType="tips" lay-verify="" placeholder="请输入照片"/>
                    <input id="picRemove" name="picRemove" type="text"
                           class="layui-input layui-hide" autocomplete="off"
                           lay-verType="tips" lay-verify="" placeholder="请输入照片"/>
                    <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                        预览图：
                        <div class="layui-upload-list" id="pic_address"></div>
                    </blockquote>
                </div>
            </div>
        </div>
        <div class="layui-form-item layui-row">
            <div class="layui-col-md4">
                <label class="layui-form-label ">备注</label>
                <div class="layui-input-block">
                    <textarea placeholder="请输入备注" class="layui-textarea" lay-verType="tips" lay-verify=""
                              id="remark" name="remark" maxlength="600" cols="" rows="5" maxlength="255"></textarea>
                </div>
            </div>
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn" lay-filter="customerEditSubmit" lay-submit>保存</button>
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
        </div>
    </form>
</script>

<!-- 违规表单弹窗 -->
<script type="text/html" id="violationsDialog">
    <form id="violationsForm" lay-filter="violationsForm" class="layui-form model-form">
        <input name="customerId" id="customerId" type="hidden"/>
        <input name="customerName" id="customerName" type="hidden"/>
        <div class="layui-form-item layui-row">
            <div class="layui-col-md12">
                <label class="layui-form-label layui-form-required">违规照片:</label>
                <div class="layui-input-block">
                    <button type="button" class="layui-btn" id="violations_pic">
                        <i class="layui-icon">&#xe67c;</i>上传图片
                    </button>
                    <input id="violations" name="picAdd" type="text" class="layui-input layui-hide" autocomplete="off"
                           lay-verType="tips" lay-verify="" placeholder=""/>
                    <input id="violationsRemove" name="violationsRemove" type="text" class="layui-input layui-hide" autocomplete="off"
                           lay-verType="tips" lay-verify="" placeholder=""/>
                    <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                        预览图：
                        <div class="layui-upload-list" id="violations_pic_address"></div>
                    </blockquote>
                </div>
            </div>
            <div class="layui-col-md12">
                <label class="layui-form-label layui-form-required">备注:</label>
                <div class="layui-input-block">
                    <textarea name="remark" id="violationsRemark" placeholder="请输入备注" class="layui-textarea"
                        maxlength="300"></textarea>
                </div>
            </div>
        </div>

        <div class="layui-form-item text-right">
            <button class="layui-btn" lay-filter="violationsEditSubmit" lay-submit>保存</button>
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
        </div>
    </form>
</script>

<!-- 缴费表单弹窗 -->
<script type="text/html" id="jfDialog">
<form id="jfForm" lay-filter="jfForm" class="layui-form model-form">
    <input name="id" id="id2" type="hidden"/>
    <input name="customerId" id="customerId2" type="hidden"/>
    <input name="customerName" id="customerName2" type="hidden"/>
    <div class="layui-form-item layui-row">
        <div class="layui-col-md4">
            <label class="layui-form-label ">总费用</label>
            <div class="layui-input-block" style="padding-top: 10px;">
                <span id="jfFrom_jf_price"></span>
            </div>
        </div>
    </div>
    <div class="layui-form-item layui-row">
        <div class="layui-col-md4">
            <label class="layui-form-label layui-form-required">缴费时间</label>
            <div class="layui-input-block">
                <input id="payTime" name="payTime" type="text" class="layui-input" autocomplete="off"
                       lay-verType="tips" lay-verify="required" maxlength="20" placeholder="请输入缴费时间"/>
            </div>
        </div>
        <div class="layui-col-md4">
            <label class="layui-form-label layui-form-required">优惠比列</label>
            <div class="layui-input-block">
<!--                <span id="jfFrom_yfk_count"></span>-->
                <input id="advanceChargeDiscount2" name="advanceChargeDiscount" type="text" class="layui-input" autocomplete="off"
                       lay-verType="tips" lay-verify="required|numberX" maxlength="20" placeholder="请输入缴费金额"/>
            </div>
        </div>
    </div>
    <div class="layui-form-item layui-row">
        <div class="layui-col-md4">
            <label class="layui-form-label layui-form-required">缴费</label>
            <div class="layui-input-block">
                <input id="pricejf" name="price" type="text" class="layui-input" autocomplete="off"
               lay-verType="tips" lay-verify="required|numberX" maxlength="20" placeholder="请输入缴费金额"/>
            </div>
        </div>
        <div class="layui-col-md4">
            <label class="layui-form-label ">缴费金额</label>
            <div class="layui-input-block" style="padding-top: 10px;">
                <span id="pricejf_2"></span>
            </div>
        </div>
    </div>
    <div class="layui-form-item layui-row">
        <div class="layui-col-md4">
            <label class="layui-form-label layui-form-required">预付</label>
            <div class="layui-input-block">
                <input id="pricejf2" name="price2" type="text" class="layui-input" autocomplete="off"
               lay-verType="tips" lay-verify="required|numberX|advanceCharge" maxlength="20" placeholder="请输入缴费金额"/>
            </div>
        </div>
        <div class="layui-col-md4">
            <label class="layui-form-label ">预付金额</label>
            <div class="layui-input-block" style="padding-top: 9px;">
                <span id="jfFrom_yfk_count_price"></span>预付剩余:<span id="jfFrom_yfk_price" style="margin-right: 7px;"></span>
            </div>
        </div>
    </div>
    <div class="layui-form-item layui-row">
        <div class="layui-col-md4">
            <label class="layui-form-label ">备注</label>
            <div class="layui-input-block">
               <textarea name="remark" id="jfRemark" placeholder="请输入备注" class="layui-textarea"
                         lay-verify="" maxlength="300"></textarea>
            </div>
        </div>
    </div>
    <div class="layui-form-item text-right">
    <button class="layui-btn" lay-filter="jfEditSubmit" lay-submit>保存</button>
    <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
    </div>
</form>
</script>

<!-- 退款费表单弹窗 -->
<script type="text/html" id="tkDialog">
    <form id="tkForm" lay-filter="tkForm" class="layui-form model-form">
        <input name="id" id="id5" type="hidden"/>
        <input name="customerId" id="customerId5" type="hidden"/>
        <input name="customerName" id="customerName5" type="hidden"/>
        <div class="layui-form-item layui-row">
            <div class="layui-col-md4">
                <label class="layui-form-label layui-form-required">退款金额</label>
                <div class="layui-input-block">
                    <input id="price5" name="price" type="text" class="layui-input" autocomplete="off"
                           lay-verType="tips" lay-verify="numberX|required" maxlength="20" placeholder="请输入退款金额"/>
                </div>
            </div>
            <div class="layui-col-md4">
                <label class="layui-form-label layui-form-required">备注</label>
                <div class="layui-input-block">
                   <textarea name="remark" id="tkRemark" placeholder="请输入备注" class="layui-textarea"
                             lay-verify="required" maxlength="300"></textarea>
                </div>
            </div>
        </div>

        <div class="layui-form-item text-right">
            <button class="layui-btn" lay-filter="tkEditSubmit" lay-submit>保存</button>
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
        </div>
    </form>
</script>

<!-- 开口费表单弹窗 -->
<script type="text/html" id="kkfDialog">
    <form id="kkfForm" lay-filter="kkfForm" class="layui-form model-form">
        <input name="id" id="id3" type="hidden"/>
        <input name="customerId" id="customerId3" type="hidden"/>
        <input name="customerName" id="customerName3" type="hidden"/>
        <div class="layui-form-item layui-row">
            <div class="layui-col-md4">
                <label class="layui-form-label layui-form-required">开口费金额</label>
                <div class="layui-input-block">
                    <input id="price3" name="price" type="text" class="layui-input" autocomplete="off"
                           lay-verType="tips" lay-verify="numberX|required" maxlength="20" placeholder="请输入开口费金额"/>
                </div>
            </div>
            <div class="layui-col-md4">
                <label class="layui-form-label layui-form-required">备注</label>
                <div class="layui-input-block">
                   <textarea name="remark" id="kkfRemark" placeholder="请输入备注" class="layui-textarea"
                             maxlength="300"></textarea>
                </div>
            </div>

        </div>

        <div class="layui-form-item text-right">
            <button class="layui-btn" lay-filter="kkfEditSubmit" lay-submit>保存</button>
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
        </div>
    </form>
</script>

<!-- 预付款表单弹窗 -->
<script type="text/html" id="yfkDialog">
    <form id="yfkForm" lay-filter="yfkForm" class="layui-form model-form">
        <input name="id" id="id4" type="hidden"/>
        <input name="customerId" id="customerId4" type="hidden"/>
        <input name="customerName" id="customerName4" type="hidden"/>
        <div class="layui-form-item layui-row">
            <div class="layui-col-md4">
                <label class="layui-form-label ">剩余金额</label>
                <div class="layui-input-block" style="padding-top: 10px;">
                    <span id="yfkForm_yfk_advanceCharge"></span>
                </div>
            </div>
        </div>
        <div class="layui-form-item layui-row">
            <div class="layui-col-md4">
                <label class="layui-form-label layui-form-required">预付金额</label>
                <div class="layui-input-block">
                    <input id="advanceCharge" name="advanceCharge" type="text" class="layui-input" autocomplete="off"
                           lay-verType="tips" lay-verify="numberX|required" maxlength="20" placeholder="请输入预付金额"/>
                </div>
            </div>
            <div class="layui-col-md4">
                <label class="layui-form-label layui-form-required">预付时间</label>
                <div class="layui-input-block">
                    <input id="advanceChargeTime" name="advanceChargeTime" type="text" class="layui-input" autocomplete="off"
                           lay-verType="tips" lay-verify="required" maxlength="20" placeholder="请输入预付时间"/>
                </div>
            </div>
        </div>

        <div class="layui-form-item layui-row">
            <div class="layui-col-md4">
                <label class="layui-form-label ">预付备注</label>
                <div class="layui-input-block">
                   <textarea name="advanceChargeRemark" id="advanceChargeRemark" placeholder="请输入预付备注" class="layui-textarea"
                             maxlength="300"></textarea>
                </div>
            </div>
        </div>

        <div class="layui-form-item text-right">
            <button class="layui-btn" lay-filter="yfkEditSubmit" lay-submit>保存</button>
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
        </div>
    </form>
</script>
<script type="text/html" id="TbStateBar">
    <input type="checkbox" value="{{d.id}}" title="{{# if(d.tbState==1){ }}正常 {{# } else { }}停报{{# } }}"
           lay-filter="TbStateBarCk" {{ d.tbState == 2 ? 'checked' : '' }}>
</script>
<!-- js部分 -->
<:include file="../common/js.html"/>

<script type="text/javascript" src="${ctxPath}/assets/js/utils.js"></script>
<script type="text/javascript">
layui.use(['layer', 'form', 'table', 'tableX', 'util', 'admin'
    ,'xmSelect','formX','dropdown','laydate', 'upload'], function () {
let $ = layui.jquery;
let layer = layui.layer;
let form = layui.form;
let table = layui.table;
let tableX = layui.tableX;
let util = layui.util;
let admin = layui.admin;
let formX = layui.formX;
let xmSelect = layui.xmSelect;
let laydate = layui.laydate;
var upload = layui.upload; //得到 upload 对象
let advanceCharge_last = 0
let advanceChargeDiscount_last = 0
form.verify({
    advanceCharge: function(value, item){ //value：表单的值、item：表单的DOM对象
        // if(!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)){
        //     return '用户名不能有特殊字符';
        // }
        // if(/(^\_)|(\__)|(\_+$)/.test(value)){
        //     return '用户名首尾不能出现下划线\'_\'';
        // }
        // if(/^\d+\d+\d$/.test(value)){
        //     return '用户名不能全为数字';
        // }
        //
        // //如果不想自动弹出默认提示框，可以直接返回 true，这时你可以通过其他任意方式提示（v2.5.7 新增）
        // if(value === 'xxx'){
        //     alert('用户名不能为敏感词');
        //     return true;
        // }
        // console.log(typeof value, typeof advanceCharge_last,value,advanceCharge_last , value > advanceCharge_last || value < 0)
        // let value22 = parseFloat(value), advanceCharge_last22 = parseFloat(advanceCharge_last), advanceChargeDiscount_last22 = parseFloat(advanceChargeDiscount_last)
        // let real_val = (value22*advanceChargeDiscount_last22/100).toFixed(2)
        // if(real_val > advanceCharge_last22 || real_val < 0){
        //     return '预付折扣后的金额只能 0到'+advanceCharge_last22+'的数字';
        // }
    }

    //我们既支持上述函数式的方式，也支持下述数组的形式
    //数组的两个值分别代表：[正则匹配、匹配不符时的提示文字]
    ,pass: [
        /^[\S]{6,12}$/
        ,'密码必须6到12位，且不能出现空格'
    ]
});

// 渲染表格
let insTb = tableX.render({
    elem: '#customerTable'
    ,url: 'customer/page'
    ,page: true
    ,height: 500//'full-100'
    ,toolbar:true
    // ,toolbar: ['<p>',
    //     <% if(so.hasPermission("customer:customer:save")){ %>
    //     '<button lay-event="add" class="layui-btn layui-btn-sm icon-btn"><i class="layui-icon">&#xe654;</i>添加</button>&nbsp;',
    //     <% } %>
    //     <% if(so.hasPermission("customer:customer:remove")){ %>
    //     '<button lay-event="del" class="layui-btn layui-btn-sm layui-btn-danger icon-btn"><i class="layui-icon">&#xe640;</i>删除</button>',
    //     <% } %>
    //     '</p>'].join('')
    ,cellMinWidth: 100
    ,cols: [[
        // {type: 'checkbox'}
        {type: 'numbers'}
        ,{field: "name",  title: "姓名", sort: false, hide:false }
        ,{field: "idCard",  title: "身份证", sort: false, hide:false,minWidth:170, templet: function (d) {
                return '\''+d.idCard+'';
            }
         }
        ,{field: "pic", title: '身份证照片', toolbar: '#picTbBar',align: 'center',sort: false, hide:false, unresize: false}
        ,{field: "phone",  title: "电话", sort: false, hide:false }
        ,{field: "heatArea",  title: "供热总面积", sort: false, hide:false }
        ,{field: "address",  title: "地址", sort: false, hide:false }
        ,{field: "payTime",  title: "缴费", sort: false, hide:false }
        ,{field: "tbState",  title: "停报", templet: '#TbStateBar', sort: false, hide:false }
        ,{field: "state",  title: "状态", sort: false, hide:true }
        ,{field: "remark",  title: "备注", sort: false, hide:false }
        ,{field: "createTime",  title: "创建时间", sort: false, hide:true ,templet: function (d) {
                return util.toDateString(d.createTime);
            }
        }
        ,{field: "createUser",  title: "创建人", sort: false, hide:true }
        ,{field: "updateTime",  title: "更新时间", sort: false, hide:true ,templet: function (d) {
                return util.toDateString(d.createTime);
            }
        }
        ,{field: "updateUser",  title: "更新人", sort: false, hide:true }
        ,{field: "deleted",  title: "del(0正常 1删除)", sort: false, hide:true }
        ,{title: '操作', toolbar: '#customerTbBar', align: 'center', minWidth: 350, fixed: 'right'}
    ]]
    , done: function (res, curr, count) {
        // console.log(res,curr, count);
        if(res.data.length > 0) {
            showHistory(res.data[0].id)
        }
    }
//     ,done: function(res, page, count){
//         //可以自行添加判断的条件是否选中
//         //这句才是真正选中，通过设置关键字LAY_CHECKED为true选中，这里只对第一行选中
// //                res.data[0]["LAY_CHECKED"]='true';
//         //下面三句是通过更改css来实现选中的效果
//         $.each(res.data, function(k,v){
//             if(v.id=="warehouse.id" || v.name=="warehouse.name"){
//                 $('tr[data-index=' + k + '] input[type="radio"]').parent().find("i").click();
// //                        $('tr[data-index=' + k + '] input[type="radio"]').prop('checked', true);
// //                        $('tr[data-index=' + k + '] input[type="radio"]').next().addClass('layui-form-checked');
// //                         form.render('radio');
//                 return false;
//             }
//         })
//     }

});

/* 修改用户状态 */
form.on('checkbox(TbStateBarCk)', function (obj) {
    var loadIndex = layer.load(2);
    // console.log(obj,$(obj.elem.outerHTML).attr('data-customerId'))
    let that = this
    admin.confirm('确定要停报吗？', function (i) {
        layer.close(i);
        let loadIndex = layer.load(2);
        admin.req('customer/tb', {
            // id: obj.elem.value,
            id: obj.elem.value,
            tbState: obj.elem.checked ? 2 : 1
        }, function (res) {
            layer.close(loadIndex);
            if (res.code === 200) {
                layer.msg(res.msg, {icon: 2});
            } else {
                layer.msg(res.msg, {icon: 1});
                // $(obj.elem).prop('checked', !obj.elem.checked);
                if(obj.elem.checked) {
                    $(obj.elem).prop('title', '停报');
                } else {
                    $(obj.elem).prop('title', '正常');
                }
                //缴费的时候需要获得content这个属性,所以在这里需要手动改变
                $(that).closest('td[data-field=tbState]')[0].dataset.content=obj.elem.checked ? 2 : 1
                form.render('checkbox');
                showHistory(that.value)
            }
        }, 'post');
    },function () {
        layer.close(loadIndex);
        if(obj.elem.checked) {
            $(obj.elem).prop('checked', false);
        } else {
            $(obj.elem).prop('checked', true);
        }
        form.render('checkbox');
    });

});

/* 点击图片放大 */
$(document).off('click.tbImg').on('click.tbImg2', '[tb-img2]', function () {
    // var imgList = table.cache['customerTable'].map(function (d) {
    //     return {
    //         alt: d.nickName,
    //         src: d.imgUrl || '../../../assets/images/head.jpg'
    //     }
    // });
    // layer.photos({photos: {data: imgList, start: $(this).data('index')}, shade: .1, closeBtn: true});
    let imgList = [{alt:'身份证', src:$(this).data('src')}]
    layer.photos({photos: {data: imgList, start: 0}, shade: .1, closeBtn: true});
});

/* 点击图片放大 */
$(document).off('click.tbImg').on('click.tbImg', '[tb-img]', function () {
    // var imgList = table.cache['customerTable'].map(function (d) {
    //     return {
    //         alt: d.nickName,
    //         src: d.imgUrl || '../../../assets/images/head.jpg'
    //     }
    // });
    // layer.photos({photos: {data: imgList, start: $(this).data('index')}, shade: .1, closeBtn: true});
    let imgList = []
    // console.log($(this).parent().html())
    layui.each($(this).parent().find('img'), function(index,item){
        imgList.push({alt:'照片', src: item.src})
    })
    // console.log(imgList)
    layer.photos({photos: {data: imgList, start: $(this).data('index')}, shade: .1, closeBtn: true,anim: 'kCATransitionFade'});
});

// 渲染表格
let payHistoryTable = tableX.render({
    elem: '#payHistoryTable'
    ,url: 'payHistory/page'
    ,page: true
    ,height: 'full-100'
    // ,toolbar: ['<p>',
    //     <% if(so.hasPermission("customer:payHistory:save")){ %>
    //     '<button lay-event="add" class="layui-btn layui-btn-sm icon-btn"><i class="layui-icon">&#xe654;</i>添加</button>&nbsp;',
    //     <% } %>
    //     <% if(so.hasPermission("customer:payHistory:remove")){ %>
    //     '<button lay-event="del" class="layui-btn layui-btn-sm layui-btn-danger icon-btn"><i class="layui-icon">&#xe640;</i>删除</button>',
    //     <% } %>
    //     '</p>'].join('')
    ,cellMinWidth: 100
    ,cols: [[
        // {type: 'checkbox'}
        {type: 'numbers'}
        ,{field: "customerId",  title: "客户id", sort: false, hide:true }
        ,{field: "customerName",  title: "姓名", sort: false, hide:false }
        ,{field: "type",  title: "类型", sort: false, hide:false }
        ,{field: "picAdd",  title: "照片", toolbar: '#payHistoryPicTbBar', sort: false, hide:false }
        ,{field: "price",  title: "金额", sort: false, hide:false }
        ,{field: "payTime",  title: "缴费时间", sort: false, hide:false }
        ,{field: "remark",  title: "备注", sort: false, hide:false }
        ,{field: "createTime",  title: "创建时间", sort: false, hide:true ,templet: function (d) {
                return util.toDateString(d.createTime);
            }
        }
        ,{field: "createUser",  title: "创建人", sort: false, hide:true }
        ,{field: "createName",  title: "创建人", sort: false, hide:false }
        ,{field: "updateTime",  title: "更新时间", sort: false, hide:true ,templet: function (d) {
                return util.toDateString(d.createTime);
            }
        }
        ,{field: "updateUser",  title: "更新人", sort: false, hide:true }
        ,{field: "deleted",  title: "del(0正常 1删除)", sort: false, hide:true }
        // ,{title: '操作', toolbar: '#payHistoryTbBar', align: 'center', minWidth: 200, fixed: 'right'}
    ]]
    ,where: {customerId: 0}
});

let cus_id = '', res_w=true, time_out;!
//监听行单击
table.on('row(customerTable)', function (obj) {
    let data = obj.data;
    if(data.id != cus_id) {
        cus_id = data.id
        res_w=true
    } else if(!res_w) {
        clearTimeout(time_out)
        time_out = setTimeout(function() { res_w = true},600)
    }
    if(res_w) {
        showHistory(data.id)
        res_w = false
    }
});
//监听行双击
// table.on('rowDouble(customerTable)', function(obj){
//     let data = obj.data;
//     showHistory(data.id)
//     // showEditModel(data);
//     // obj.tr.find("a[lay-event=edit]").trigger("click");//会跳出来两个一样的框 这个不好用
//     //obj.tr.toggleClass('layui-table-click').siblings().removeClass('layui-table-click');//选中行
// });

function showHistory(customerId) {
    //执行重载
    table.reload('payHistoryTable', {
        page: {
            curr: 1 //重新从第 1 页开始
        }
        ,url: 'payHistory/page'
        ,where: {
            customerId: customerId,
            // key: {
            //     customerId: customerId
            // }
        }
    }, 'data');
}

// 搜索
form.on('submit(customerTbSearch)', function (data) {
    insTb.reload({where: data.field, page: {curr: 1}});
    return false;
});

form.on('select(payTimeSearch)', function(data){
    $("#customerTbSearch").click();
});
form.on('select(tbStateSearch)', function(data){
    $("#customerTbSearch").click();
});
$('.search_key').bind('keypress',function(event){
    if(event.keyCode == "13")
    {
        $("#customerTbSearch").click();
    }
});

// 工具条点击事件
table.on('tool(customerTable)', function (obj) {
    if ('edit' === obj.event) { // 修改
        showEditModel(obj.data);
    } else if ('del' === obj.event) { // 删除
        doDel(obj);
    } else if ('tb' === obj.event) { // 停报
        doTb(obj);
    } else if ('jf' === obj.event) { // 缴费
        showjfModel(obj);
    } else if ('kkf' === obj.event) { // 开口费
        showkkfModel(obj.data)
    } else if ('tk' === obj.event) { // 退款
        showtkModel(obj.data)
    } else if ('wg' === obj.event) { // 违规
        showViolationsModel(obj.data);
    } else if ('ysk' === obj.event) { // 预付款
        showAdvanceCollectionModel(obj.data);
    }
});

// 添加
$('#btnAdd').click(function () {
    showEditModel();
});


/* 表格头工具栏点击事件 */
table.on('toolbar(customerTable)', function (obj) {
    if ('add' === obj.event) { // 添加
        showEditModel();
    } else if ('del' === obj.event) { // 删除
        let checkRows = table.checkStatus('customerTable');
        if (!checkRows || !checkRows.data || 0 === checkRows.data.length) {
            return layer.msg('请选择要删除的数据', {icon: 2, anim: 6});
        }
        let ids = checkRows.data.map(function (d) {
            return d.id;
        });
        doDel({ids: 'true', id: ids.join(",")});
    }
});

function totalPrice() {
    // $('#illustrate').html('总费用:商用面积*40 + 民用面积*25 + 商用热损(商用面积*40*0.2) + 民用热损(民用面积*25*0.2)');
    // $('#illustrate').html($('#commercial').val()+'<br/>');
    let tt = $('#commercial').val()*40 +$('#civil').val()*25
            + $('#commercialUnuse').val()*40*0.2 + $('#civilUnuse').val()*25*0.2
    $('#price').val(tt.toFixed(2))
}
$("body").on("click", ".pic_remove_class", function() {
    const dataset = $(this)[0].dataset
    const datasetSrc = dataset.src
    const picId = dataset.picid
    const picRemoveId = dataset.picremoveid
    let pic_tmp_str = $('#'+picId+'').val()
    pic_tmp_str = pic_tmp_str.replace(','+datasetSrc,'')
        .replace(datasetSrc+',','')
        .replace(datasetSrc,'')
    $(this).parent().parent().remove();
    $('#'+picId+'').val(pic_tmp_str)
    if(dataset.picremoveactual=='true') {
        admin.req('../file/remove', {'path': datasetSrc}, function (res) {
            if (0 === res.code) {
                layer.msg(res.msg, {icon: 1});
                // insTb.reload({page: {curr: 1}});
            } else {
                layer.msg(res.msg, {icon: 2, anim: 6});
            }
        }, 'post');
    } else {
        $('#'+picRemoveId+'').val($('#'+picRemoveId+'').val()+','+datasetSrc)
    }
});
// 显示编辑弹窗
function showEditModel(mData) {
    admin.open({
        type: 1,
        title: (mData ? '修改' : '添加') + '客户管理',
        maxmin:true,
        closeBtn:1,
        resize: true,
        shade: [0.8, "#393D49"],
        shadeClose:true,
        area:["1000px","770px"],
        content: $('#customerEditDialog').html(),
        success: function (layero, dIndex) {
            // 回显表单数据
            form.val('customerEditForm', mData);
            // console.log(mData)
            // 表单提交事件
            try {
                // $("#pic_address").attr('src','/file/'+mData.pic)
                let ad = mData.pic.split(',')
                ad.forEach((index2,item2) => {
                    if(index2==''||index2==undefined){return true}
                    $('#pic_address').append('<span style="position: relative;margin-right: 7px;">' +
                        '<img src="/file/' + index2 +'" alt="照片'
                        +'" class="layui-upload-img" style="width: 150px;height: 150px;"> ' +
                        '<span class="layui-layer-setwin" style="top: -51px;right: 21px;">' +
                        '<a class="layui-layer-ico  layui-layer-close2 pic_remove_class" ' +
                        'data-src="'+index2+'" data-picRemoveActual="false" ' +
                        'data-picId="pic" data-picRemoveId="picRemove" '  +
                        'href="javascript:void(0);">' +
                        '</a></span></span> ')
                })
            } catch (e) {
            }
            $("#card_update").click(function(){
                layer.confirm("是否修改id为"+$("#card").val(), function(index_card_update) {
                    mData.checked=$("#card").val()
                    admin.req('customer/cardUpdate', mData, function (res) {
                        layer.close(index_card_update);
                        if (0 === res.code) {
                            layer.close(dIndex);
                            layer.msg(res.msg, {icon: 1});
                            insTb.reload({page: {curr: 1}});
                        } else {
                            layer.msg(res.msg, {icon: 2, anim: 6});
                        }
                    }, 'post');
                })
            })
            let divPayTime = true
            <% if(so.hasPermission("customer:customer:paytime")){ %>
            divPayTime = false
            <% } %>
            if(divPayTime) {
                $('#divPayTime').addClass('layui-hide')
            }
            laydate.render({
                elem: '#payTimelie'
                ,type: 'year'
                ,done: function (value,date,endDate) {

                }
            });

            totalPrice()
            $('#commercial,#civil,#commercialUnuse,#civilUnuse').blur(function(){
                totalPrice()
            })
            $('#commercial,#civil,#commercialUnuse,#civilUnuse').on('input',function(e){
                totalPrice()
            });

            //阻止表单回车提交,刷卡后表单默认会提交
            // $("input").keypress(function (e) {
            //     var keyCode = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
            //     if (keyCode == 13) {
            //         for (var i = 0; i < this.form.elements.length; i++) {
            //             if (this == this.form.elements[i]) break;
            //         }
            //         i = (i + 1) % this.form.elements.length;
            //         this.form.elements[i].focus();
            //         return false;
            //     } else {
            //         return true;
            //     }
            // });


            form.on('submit(customerEditSubmit)', function (data) {
                let loadIndex = layer.load(2);
                admin.req(mData ? 'customer/update' : 'customer/save', data.field, function (res) {
                    layer.close(loadIndex);
                    if (0 === res.code) {
                        layer.close(dIndex);
                        layer.msg(res.msg, {icon: 1});
                        insTb.reload({page: {curr: 1}});
                    } else {
                        layer.msg(res.msg, {icon: 2, anim: 6});
                    }
                }, 'post');
                $("button[lay-filter='customerEditSubmit']").attr("disabled","disabled");
                setTimeout(function(){$("button[lay-filter='customerEditSubmit']").removeAttr("disabled");}, 1000 );
                return false;
            });

            //创建一个上传组件
            upload.render({
                elem: '#pic_upload'
                ,url: '../file/upload'
                ,multiple: true
                ,before: function(obj){
                    // if(mData==undefined) {
                    //     layer.alert('', {
                    //         skin: 'layui-layer-molv' //样式类名
                    //         ,closeBtn: 0
                    //     }, function(){
                    //         layer.alert('偶吧深蓝style', {
                    //             skin: 'layui-layer-lan'
                    //             ,closeBtn: 0
                    //             ,anim: 4 //动画类型
                    //         });
                    //     });
                    //     return false;
                    // }
                    //预读本地文件示例，不支持ie8
                    obj.preview(function(index, file, result){
                        // console.log(index, file.name, result)
                        $('#pic_address').append('<span style="position: relative;margin-right: 7px;">' +
                            '<img src="' + result +'" alt="照片'
                            +'" class="layui-upload-img" style="width: 150px;height: 150px;"> ' +
                            '<span class="layui-layer-setwin" style="top: -51px;right: 21px;">' +
                            '<a class="layui-layer-ico  layui-layer-close2 pic_remove_class" ' +
                            'data-src="" data-picRemoveActual="true" ' +
                            'data-picId="pic" data-picRemoveId="picRemove" '  +
                            'href="javascript:void(0);" οnclick="removePic(this)">' +
                            '</a></span></span> ')

                        // $('#pic_address').append('<img src="'
                        //     + result +'" alt="'+ file.name
                        //     +'" class="layui-upload-img" style="width: 150px;height: 150px;"> ')

                    });
                    //this.data = {'name':mData.name}
                }
                ,done: function(res, index, upload){ //上传后的回调
                    // console.log(res, index, upload)
                    let violations_pic = ''
                    if($("#pic").val()!=''){
                        violations_pic += $("#pic").val() + ','
                    }
                    $("#pic").val(violations_pic+res.url)
                    $('#pic_address>span:last>span>a')[0].dataset.src=res.url
                }
                ,accept: 'images' //允许上传的文件类型
                ,size: 600  //最大允许上传的文件大小
                //,……
            })


            // 禁止弹窗出现滚动条
            //$(layero).children('.layui-layer-content').css('overflow', 'visible');
        }
    });
}

// 违规弹窗
function showViolationsModel(mData) {
    admin.open({
        type: 1,
        title: '违规',
        maxmin:true,
        closeBtn:1,
        resize: true,
        shade: [0.8, "#393D49"],
        shadeClose:true,
        area:["900px","550px"],
        content: $('#violationsDialog').html(),
        success: function (layero, dIndex) {
            mData.remark='';
            // 回显表单数据
            form.val('violationsForm', mData);
            $('#customerId').val(mData.id)
            $('#customerName').val(mData.name)
            // 表单提交事件
            form.on('submit(violationsEditSubmit)', function (data) {
                let loadIndex = layer.load(2);
                admin.req('payHistory/saveWg', data.field, function (res) {
                    layer.close(loadIndex);
                    if (0 === res.code) {
                        layer.close(dIndex);
                        layer.msg(res.msg, {icon: 1});
                        insTb.reload({page: {curr: 1}});
                    } else {
                        layer.msg(res.msg, {icon: 2, anim: 6});
                    }
                }, 'post');
                $("button[lay-filter='violationsEditSubmit']").attr("disabled","disabled");
                setTimeout(function(){$("button[lay-filter='violationsEditSubmit']").removeAttr("disabled");}, 1000 );
                return false;
            });

            //创建一个上传组件
            upload.render({
                elem: '#violations_pic'
                ,url: '../file/upload'
                ,multiple: true
                ,before: function(obj){
                    //预读本地文件示例，不支持ie8
                    obj.preview(function(index, file, result){
                        // console.log(index, file.name, result)
                        $('#violations_pic_address').append(
                            '<span style="position: relative;margin-right: 7px;">' +
                            '<img src="' + result +'" alt="照片'
                            +'" class="layui-upload-img" style="width: 150px;height: 150px;"> ' +
                            '<span class="layui-layer-setwin" style="top: -51px;right: 21px;">' +
                            '<a class="layui-layer-ico  layui-layer-close2 pic_remove_class" ' +
                            'data-src="" data-picRemoveActual="true" ' +
                            'data-picId="violations" data-picRemoveId="violationsRemove" '  +
                            'href="javascript:void(0);" οnclick="removePic(this)">' +
                            '</a></span></span> ')
                    });
                    // this.data = {'name':mData.name}
                }
                ,done: function(res, index, upload){ //上传后的回调
                    // console.log(res, index, upload)
                    let violations_pic = ''
                    if($("#violations").val()!=''){
                        violations_pic += $("#violations").val() + ','
                    }
                    $("#violations").val(violations_pic+res.url)
                    $('#violations_pic_address>span:last>span>a')[0].dataset.src=res.url
                }
                ,accept: 'images' //允许上传的文件类型
                ,size: 600  //最大允许上传的文件大小
                //,……
            })



            // 禁止弹窗出现滚动条
            //$(layero).children('.layui-layer-content').css('overflow', 'visible');
        }
    });
}

// 缴费弹窗
function showjfModel(obj2) {
    let mData = obj2.data
    admin.open({
        type: 1,
        title: '缴费',
        maxmin:true,
        closeBtn:1,
        resize: true,
        shade: [0.8, "#393D49"],
        shadeClose:true,
        area:["900px","550px"],
        content: $('#jfDialog').html(),
        success: function (layero, dIndex) {
            mData.remark='';
            advanceCharge_last = mData.advanceCharge ?  mData.advanceCharge: 0
            // advanceChargeDiscount_last = mData.advanceChargeDiscount ?  mData.advanceChargeDiscount: 100
            // 回显表单数据
            form.val('jfForm', mData);
            $('#customerId2').val(mData.id)
            $('#customerName2').val(mData.name)
            $('#pricejf').val(0)
            $('#pricejf2').val(0)

            $('#jfFrom_yfk_price').text(advanceCharge_last)
            // $('#jfFrom_yfk_count').text(advanceChargeDiscount_last)
            $('#jfFrom_jf_price').text(mData.price)


            $('#pricejf,#advanceChargeDiscount2').bind("input propertychange",function () {
                let pricejf222 = (parseFloat($('#pricejf').val())* parseFloat($('#advanceChargeDiscount2').val())/100).toFixed(2)
                pricejf222 = pricejf222?pricejf222:0
                pricejf222 = pricejf222!='NaN'?pricejf222:0
                $('#pricejf_2').text(pricejf222)

                // if(pricejf222=='NaN' || pricejf222==''){
                //     $('#pricejf').val(0)
                // }
            })

            $('#pricejf2, #advanceChargeDiscount2').bind("input propertychange",function () {
                let pricejf222 = (parseFloat($('#pricejf2').val())* parseFloat($('#advanceChargeDiscount2').val())/100).toFixed(2)
                // let pricejf222 = (parseFloat($('#pricejf2').val())* advanceChargeDiscount_last/100).toFixed(2)
                pricejf222 = pricejf222?pricejf222:0
                pricejf222 = pricejf222!='NaN'?pricejf222:0
                $('#jfFrom_yfk_count_price').text(pricejf222)

                // if(pricejf222=='NaN' || pricejf222==''){
                //     $('#pricejf2').val(0)
                // }
            })

            // let cont3 = $('div[lay-id="customerTable"] div'
            //     +obj2.tr.selector+'>td[data-field="tbState"]')[0]
            //     .dataset.content
            // if(cont3==2) {
            //     $('#pricejf').val($('#pricejf').val()*0.2)
            // }
            laydate.render({
                elem: '#payTime'
                ,type: 'year'
                ,done: function (value,date,endDate) {

                }
            });
            $('#payTime').val(new Date().getFullYear())
            // 表单提交事件
            form.on('submit(jfEditSubmit)', function (data) {
                let p_111 = $('#pricejf_2').text()==''?0:$('#pricejf_2').text() //缴费
                let p_222 = $('#jfFrom_yfk_count_price').text()==''?0:$('#jfFrom_yfk_count_price').text() //预付
                data.field.price = p_111
                data.field.advanceCharge = p_222
                data.field.advanceChargeDiscount = mData.advanceChargeDiscount

                let loadIndex = layer.load(2);
                admin.req('customer/jf', data.field, function (res) {
                    layer.close(loadIndex);
                    if (0 === res.code) {
                        layer.close(dIndex);
                        layer.msg(res.msg, {icon: 1});
                        insTb.reload({page: {curr: 1}});
                        showHistory(mData.id)
                    } else {
                        layer.msg(res.msg, {icon: 2, anim: 6});
                    }
                }, 'post');
                $("button[lay-filter='jfEditSubmit']").attr("disabled","disabled");
                setTimeout(function(){$("button[lay-filter='jfEditSubmit']").removeAttr("disabled");}, 1000 );
                return false;
            });
            // 禁止弹窗出现滚动条
            //$(layero).children('.layui-layer-content').css('overflow', 'visible');
        }
    });
}


// 退款费弹窗
function showtkModel(mData) {
    admin.open({
        type: 1,
        title: '退款',
        maxmin:true,
        closeBtn:1,
        resize: true,
        shade: [0.8, "#393D49"],
        shadeClose:true,
        area:["900px","550px"],
        content: $('#tkDialog').html(),
        success: function (layero, dIndex) {
            mData.remark='';
            mData.price='';

            // 回显表单数据
            form.val('tkForm', mData);
            $('#customerId5').val(mData.id)
            $('#customerName5').val(mData.name)
            // 表单提交事件
            form.on('submit(tkEditSubmit)', function (data) {
                let loadIndex = layer.load(2);
                admin.req('customer/tk', data.field, function (res) {
                    layer.close(loadIndex);
                    if (0 === res.code) {
                        layer.close(dIndex);
                        layer.msg(res.msg, {icon: 1});
                        insTb.reload({page: {curr: 1}});
                    } else {
                        layer.msg(res.msg, {icon: 2, anim: 6});
                    }
                }, 'post');
                $("button[lay-filter='tkEditSubmit']").attr("disabled","disabled");
                setTimeout(function(){$("button[lay-filter='tkEditSubmit']").removeAttr("disabled");}, 1000 );
                return false;
            });
            // 禁止弹窗出现滚动条
            //$(layero).children('.layui-layer-content').css('overflow', 'visible');
        }
    });
}

// 开口费弹窗
function showkkfModel(mData) {
    admin.open({
        type: 1,
        title: '开口费',
        maxmin:true,
        closeBtn:1,
        resize: true,
        shade: [0.8, "#393D49"],
        shadeClose:true,
        area:["900px","550px"],
        content: $('#kkfDialog').html(),
        success: function (layero, dIndex) {
            mData.remark='';
            mData.price='';

            // 回显表单数据
            form.val('kkfForm', mData);
            $('#customerId3').val(mData.id)
            $('#customerName3').val(mData.name)
            // 表单提交事件
            form.on('submit(kkfEditSubmit)', function (data) {
                let loadIndex = layer.load(2);
                admin.req('customer/kkf', data.field, function (res) {
                    layer.close(loadIndex);
                    if (0 === res.code) {
                        layer.close(dIndex);
                        layer.msg(res.msg, {icon: 1});
                        insTb.reload({page: {curr: 1}});
                    } else {
                        layer.msg(res.msg, {icon: 2, anim: 6});
                    }
                }, 'post');
                $("button[lay-filter='kkfEditSubmit']").attr("disabled","disabled");
                setTimeout(function(){$("button[lay-filter='kkfEditSubmit']").removeAttr("disabled");}, 1000 );
                return false;
            });
            // 禁止弹窗出现滚动条
            //$(layero).children('.layui-layer-content').css('overflow', 'visible');
        }
    });
}

// 预付款弹窗
function showAdvanceCollectionModel(mData) {
    admin.open({
        type: 1,
        title: '预付款',
        maxmin:true,
        closeBtn:1,
        resize: true,
        shade: [0.8, "#393D49"],
        shadeClose:true,
        area:["900px","550px"],
        content: $('#yfkDialog').html(),
        success: function (layero, dIndex) {
            $('#customerId4').val(mData.id)
            $('#customerName4').val(mData.name)
            $('#yfkForm_yfk_advanceCharge').text(mData.advanceCharge)

            mData.advanceChargeTime='';
            mData.advanceCharge='';
            mData.advanceChargeRemark='';
            // 回显表单数据
            form.val('yfkForm', mData);
            // 表单提交事件
            form.on('submit(yfkEditSubmit)', function (data) {
                let loadIndex = layer.load(2);
                admin.req('customer/yfk', data.field, function (res) {
                    layer.close(loadIndex);
                    if (0 === res.code) {
                        layer.close(dIndex);
                        layer.msg(res.msg, {icon: 1});
                        insTb.reload({page: {curr: 1}});
                    } else {
                        layer.msg(res.msg, {icon: 2, anim: 6});
                    }
                }, 'post');
                $("button[lay-filter='yfkEditSubmit']").attr("disabled","disabled");
                setTimeout(function(){$("button[lay-filter='yfkEditSubmit']").removeAttr("disabled");}, 1000 );
                return false;
            });


            laydate.render({
                elem: '#advanceChargeTime'
                ,type: 'datetime'
                ,done: function (value,date,endDate) {

                }
            });
            // 禁止弹窗出现滚动条
            //$(layero).children('.layui-layer-content').css('overflow', 'visible');
        }
    });
}


// 删除
function doDel(obj) {
    if (obj.ids) {  // 批量删除
        admin.confirm('确定要删除选中数据吗？', function (i) {
            layer.close(i);
            let loadIndex = layer.load(2);
            admin.req('customer/remove', obj/*JSON.stringify(obj.ids)*/, function (res) {
                layer.close(loadIndex);
                if (0 === res.code) {
                    layer.msg(res.msg, {icon: 1});
                    insTb.reload({page: {curr: 1}});
                } else {
                    layer.msg(res.msg, {icon: 2, anim: 6});
                }
            }, 'post');
        });
    } else {  // 单个删除
         let loadIndex = layer.load(2);
         $.get('customer/remove', {id: obj.data.id}, function (res) {
             layer.close(loadIndex);
             if (0 === res.code) {
                 layer.msg(res.msg, {icon: 1});
                 insTb.reload({page: {curr: 1}});
             } else {
                 layer.msg(res.msg, {icon: 2, anim: 6});
             }
         });
     }
}

//停报
function doTb(obj) {
    admin.confirm('确定要停报'+obj.data.name+'吗？', function (i) {
        layer.close(i);
        let loadIndex = layer.load(2);
        admin.req('customer/tb', obj.data/*JSON.stringify(obj.ids)*/, function (res) {
            layer.close(loadIndex);
            if (0 === res.code) {
                layer.msg(res.msg, {icon: 1});
                insTb.reload({page: {curr: 1}});
                payHistoryTable.reload({where: {customerId: obj.data.id}, page: {curr: 1}})
                try {
                    top.payHistoryTableReload()
                } catch (e) {
                }
            } else {
                layer.msg(res.msg, {icon: 2, anim: 6});
            }
        }, 'post');
    });
}

});
</script>
</body>
</html>
